// UsbPhoneCtrl.cpp : Implementation of CUsbPhoneCtrlApp and DLL registration.

#include "stdafx.h"
#include "UsbPhoneCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CUsbPhoneCtrlApp NEAR theApp;

const GUID CDECL BASED_CODE _tlid =
		{ 0x1014e737, 0x95, 0x4424, { 0xa2, 0xe5, 0x64, 0x80, 0x24, 0xbf, 0xd7, 0x31 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 2;


////////////////////////////////////////////////////////////////////////////
// CUsbPhoneCtrlApp::InitInstance - DLL initialization
HWND hChildWnd = NULL;

LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch( message )
   {
   case WM_CREATE:
      // SetTimer(hWnd,1007,500,NULL);
       break;
   case WM_TIMER:
       if( wParam == 1007 )
       {
          // ::PostThreadMessage(idThread,msg,wParam,lParm);
       }
       break;
   }
   return DefWindowProc(hWnd, message, wParam, lParam);
}

BOOL InitUsbPnpMsgWnd(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;


    if( hChildWnd )  return TRUE;

    wcex.cbSize         = sizeof(WNDCLASSEX); 
	wcex.style			= WS_OVERLAPPED ;
	wcex.lpfnWndProc	= (WNDPROC)ChildWndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= NULL;
	wcex.hCursor		= NULL;
	wcex.hbrBackground	= NULL;
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= _T("ygrUsbPnpMessageWindow");
	wcex.hIconSm		= NULL;

    RegisterClassEx(&wcex);   
    hChildWnd = CreateWindowEx( WS_EX_TOOLWINDOW, _T("ygrUsbPnpMessageWindow"), _T(""),
						   WS_OVERLAPPEDWINDOW, 0, 0, 200, 200, NULL, NULL, 0, NULL);
   
    UnregisterClass(wcex.lpszClassName,NULL);
    if (!hChildWnd)
    {
        return FALSE;
    }
    
    ShowWindow(hChildWnd, SW_HIDE);// SW_SHOWNORMAL);
   
    return TRUE;
}


BOOL CUsbPhoneCtrlApp::InitInstance()
{
	BOOL bInit = COleControlModule::InitInstance();

    InitUsbPnpMsgWnd(this->m_hInstance);
    

	if (bInit)
	{
		// TODO: Add your own module initialization code here.
	}

	return bInit;
}


////////////////////////////////////////////////////////////////////////////
// CUsbPhoneCtrlApp::ExitInstance - DLL termination

int CUsbPhoneCtrlApp::ExitInstance()
{
    KillTimer(hChildWnd,1007);
    DestroyWindow(hChildWnd);
	// TODO: Add your own module termination code here.

	return COleControlModule::ExitInstance();
}


/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}


/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	AFX_MANAGE_STATE(_afxModuleAddrThis);

	if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
		return ResultFromScode(SELFREG_E_TYPELIB);

	if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
		return ResultFromScode(SELFREG_E_CLASS);

	return NOERROR;
}
